using Godot;
using System;

public partial class PlayerBase : Node3D
{
	[Export] public int MaxHealth = 5;
	[Export] public int TurretCost = 100;

	private int _currentHealth;
	private Label3D _label3D;
	private Color colorRed = new Color(Colors.Red);
	private Color colorWhite = new Color(Colors.White);

	public int CurrentHealth
	{
		get => _currentHealth;
		set
		{
			_currentHealth = value;
			// GD.Print("生命值改变！");
			_label3D.Text = value + "/" + MaxHealth;

			Color color = colorRed.Lerp(colorWhite, (float)value / MaxHealth);
			_label3D.Modulate = color;
			//  重新加载游戏
			if (value < 1)
			{
				GetTree().ReloadCurrentScene();
			}
		}
	}


	public override void _Ready()
	{
		_label3D = GetNode<Label3D>("Label3D");
		CurrentHealth = MaxHealth;
	}

	public void takeDamage()
	{
		// GD.Print("takeDamage");
		CurrentHealth -= 1;
	}
}
